package member.login;
import java.io.*;
import java.sql.*;
import java.util.*;

import javax.servlet.*;
import javax.servlet.http.*;

import db.member.*;
public class Login extends HttpServlet{

	public void doPost(HttpServletRequest request,
			  HttpServletResponse response){
		 System.out.println("sdfsadf");
			  try {
				  requestPro(request,response);
			   } catch (Exception e) {
			    e.printStackTrace();
			   } 
			 }
	 public void doGet(HttpServletRequest request,
	  HttpServletResponse response){
	  try {requestPro(request,response);
	   } catch (Exception e) {
	    e.printStackTrace();
	   }
	 }
	
	 public void requestPro(HttpServletRequest request,
			  HttpServletResponse response) throws Exception{
		
			  MemberDAO dao=new MemberDAO();
			  MemberBean bean=new MemberBean();
			  HttpSession session=request.getSession();
			  int result=-1;
			  request.setCharacterEncoding("euc-kr");
			   bean.setShop_id(request.getParameter("shop_id"));
		   	   bean.setShop_pswd(request.getParameter("shop_pswd"));
			   result=dao.empLogin(bean);
			   dao.empName(bean);
				 System.out.println("sdfsadf");
			   if(result==0){
		   			response.setContentType("text/html;charset=euc-kr");
			   		PrintWriter out=response.getWriter();
			   		out.println("<script>");
			   		out.println("alert('로그인되었습니다.');");
			   		out.println("location.href='login.jsp';");
			   		out.println("</script>");
			   		out.close();
			   		return;
		   		}else if(result==-1){
		   			response.setContentType("text/html;charset=euc-kr");
			   		PrintWriter out=response.getWriter();
			   		out.println("<script>");
			   		out.println("alert('로그인실패.');");
			   		out.println("location.href='login.jsp';");
			   		out.println("</script>");
			   		out.close();
			   		return;
			   	}
			  session.setAttribute("shop_id", bean.getShop_id());
			  session.setAttribute("shop_name", bean.getShop_name());
			  session.setAttribute("shop_pswd", bean.getShop_pswd());
			
			  RequestDispatcher rd= request.getRequestDispatcher("/harvest/index01.jsp");
					  rd.forward(request, response);
		}
}
